!
      subroutine tiefaccont(ntie,tieset,nset,set,istartset,
     &  iendset,ialset,itiefac,islavsurf)
!
!     Determine itiefac and islavsurf for slave surface
!     Author:Li,Yang
!
      implicit none
!
      character*81 tieset(3,*),slavset,set(*)
!
      integer ncont,ntie,i,j,k,l,nset,istartset(*),iendset(*),ialset(*),
     &  iright,itietri(2,ntie),nelem,jface,indexe,nope,m,
     &  ifaceq(8,6),ifacet(6,4),ifacew1(4,5),ifacew2(8,5),node,
     &  ntrifac,itrifac3(3,1),itrifac4(3,2),itrifac6(3,4),itrifac8(3,6),
     &  itrifac(3,6),nnodelem,nface,nodef(8),
     &  itiefac(2,*),islavsurf(2,*),facecount,slavcount,islav
!
!     nodes per face for hex elements
!
      data ifaceq /4,3,2,1,11,10,9,12,
     &            5,6,7,8,13,14,15,16,
     &            1,2,6,5,9,18,13,17,
     &            2,3,7,6,10,19,14,18,
     &            3,4,8,7,11,20,15,19,
     &            4,1,5,8,12,17,16,20/
!
!     nodes per face for tet elements
!
      data ifacet /1,3,2,7,6,5,
     &             1,2,4,5,9,8,
     &             2,3,4,6,10,9,
     &             1,4,3,8,10,7/
!
!     nodes per face for linear wedge elements
!
      data ifacew1 /1,3,2,0,
     &             4,5,6,0,
     &             1,2,5,4,
     &             2,3,6,5,
     &             4,6,3,1/
!
!     nodes per face for quadratic wedge elements
!
      data ifacew2 /1,3,2,9,8,7,0,0,
     &             4,5,6,10,11,12,0,0,
     &             1,2,5,4,7,14,10,13,
     &             2,3,6,5,8,15,11,14,
     &             4,6,3,1,12,15,9,13/
!
      ncont=0
      facecount=1
!
!     counters for new fields islavsurf and itiefac
!
      do i=1,ntie
!
!        check for contact conditions
!
         if(tieset(1,i)(81:81).eq.'C') then
            slavset=tieset(2,i)
!
!           determining the slave surface
!
            do j=1,nset
               if(set(j).eq.slavset) exit
            enddo
            if(j.gt.nset) then
               write(*,*) '*ERROR in tiefaccont: slave surface'
               write(*,*) '       does not exist'
               stop
            endif
            islav=j
!
            slavcount=0
            itiefac(1,i)=facecount
            do j=istartset(islav),iendset(islav)
               if(ialset(j).gt.0) then
!               put all the num made of element num and face num 
!               of slave face into islavsurf(1,*)               
                  slavcount=slavcount+1
                  islavsurf(1,itiefac(1,i)+slavcount)=ialset(j)
                  facecount=facecount+1
               endif
            enddo
            itiefac(2,i)=facecount
!
            if(itiefac(1,i).eq.itiefac(2,i)) then
               itiefac(1,i)=0
               itiefac(2,i)=0
            endif
         endif
      enddo
      return
      end